package com.gaohe.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gaohe.common.R;
import com.gaohe.pojo.Comment;
import com.gaohe.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@Slf4j
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    /**
     * 根据商品 id 获取 评论列表
     * @param shopId
     * @return
     */
    @GetMapping("/getCommentsByShopId/{shopId}")
    public R getCommentsByShopId(@PathVariable Long shopId){
        return R.success(commentService.getCommentsByShopId(shopId));
    }

    /**
     * 新增评论
     * @param comment
     * @return
     */
    @PostMapping("/submitComment")
    public R submitComment(@RequestBody Comment comment){
        System.err.println(comment);
        comment.setCreateTime(LocalDateTime.now());
        return R.success(commentService.save(comment));
    }
}
